package com.dy.nygl.controller;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dy.nygl.pojo.Building;
import com.dy.nygl.service.BuildingService;

@Controller
@RequestMapping("/build")
public class BuildingController {

	@Resource(name="buildingService")
	private BuildingService buildingServie;
	
	@RequestMapping("/getBuilding.action")
	@ResponseBody  
	public List<Map<String, Object>> getBuilding(HttpServletRequest request,HttpServletResponse response) {
		System.out.println("==============================Test----Start");
		if(request.getParameter("regionId")!=null && !request.getParameter("regionId").equals("")) {
			int regionId = Integer.parseInt(request.getParameter("regionId"));
			List<Building> buildList = buildingServie.getBuilding(regionId);
			
			if(buildList != null) {
				List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
				for(int i=0; i<buildList.size(); i++) {
					Map<String, Object> map = new LinkedHashMap <String, Object>();
					map.put("id",buildList.get(i).getId());
					map.put("name", buildList.get(i).getName());
					list.add(map);					
				}	
				
				System.out.println("==================="+list);
				return list;
			}
		}	
		System.out.println("=======================Test---Success");
		return null;
	}
}
